package com.bi.design.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bi.design.entity.Device;
import com.bi.design.mapper.DeviceMapper;
import com.bi.design.service.DeviceService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
@RequiredArgsConstructor
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
    private final DeviceMapper deviceMapper;


    @Override
    public String addAndEdit(Device dto) {
        if (StringUtils.isBlank(dto.getDeviceCode())) {
            // 设定编号
            dto.setDeviceCode(RandomStringUtils.randomAlphanumeric(12));
            deviceMapper.insert(dto);
        } else {
            deviceMapper.updateById(dto);
        }
        return dto.getDeviceCode();
    }

}
